package studio.wetrack.dinner.domain;

import lombok.Data;

import javax.persistence.*;

/**
 * Created by zhanghong on 2017/8/12.
 */
@Data
@Entity(name = "dish_inventory")
public class DishInventory {

    @Id
    long id;
    int number;
//    @Column(name = "dish_id")
//    long dishId;

    @ManyToOne
    @JoinColumn(name = "dish_id")
    Dish dish;

    public synchronized Dish getOneDish(){
        if(number > 0) {
            number--;
            return dish.getOneInstance();
        }
        return null;
    }
}
